﻿#ifndef _SUDOKU_COMMAND_H_
#define _SUDOKU_COMMAND_H_

#include <memory>
#include "common.h"
#include "scene.h"
class CScene;
class CCommand
{
public:
    CCommand(CScene* pScene) : m_pScene(pScene) {}
    CCommand(CScene* scene) : _scene(scene) {}
    CCommand(CScene *scene, const point_t &point, int preValue, int curValue)
        : _scene(scene), _point(point), _preValue(preValue), _curValue(curValue) {}
~CCommand();
    void processCommand(const std::string& command);
    bool execute(int value){
        int lastValue;
        if (_scene->setCurValue(value, lastValue))
        {
            _preValue = lastValue;
            _curValue = value;
            return true;
        }
        return false;
    }
    void someFunction(CScene* scene) {
        scene->decreaseScore(10); //调用公用方法来减少分数
    }
    void undo()
    {
        _scene->setPointValue(_point,_preValue);
        if(_curValue == _scene->getCorrectValue(_point))
        {
            _scene->decreaseScore(10);
        }
    };
    point_t getPoint() { return _stPoint; }
    int getPreValue() { return _nPreValue; }
    int getCurValue() { return _nCurValue; }
    void setPoint(const point_t &point) { _stPoint = point; }
    void setPreValue(int preValue) { _nPreValue = preValue; }
    void setCurValue(int curValue) { _nCurValue = curValue; }

private:
    CScene* _pOwner;
    CScene* m_pScene;
    CScene* _scene;
    point_t _stPoint;
    point_t _point;
    int _preValue;
    int _curValue;
    int _nPreValue;
    int _nCurValue;  // actually the member is never used
};

#endif